echo "开始创建目录 /home/www"
mkdir /home/www
echo "创建目录 /home/www 完成"

echo "切换到 /home/www 目录"
cd /home/www

echo "开始创建 any_api_server.go 文件并写入代码"
cat << 'EOF' > any_api_server.go
package main

import (
    "github.com/gin-gonic/gin"
    "math/rand"
)

type Data struct {
    Name, Address, Mobile, Money, Like, ID_card string
    ID                                         int
}

func randomPath(c *gin.Context) {
    jsonData := []Data{
        {
            ID:       0,
            ID_card:  "6221881460008225654",
            Name:     "徐梓晨",
            Address:  "北京",
            Mobile:   "15001263227",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       1,
            ID_card:  "6221881460008298745",
            Name:     "向华强",
            Address:  "上海",
            Mobile:   "15998167380",
            Money:    "30",
            Like:     "篮球",
        },
		 {
            ID:       12,
            ID_card:  "6221881460008225654",
            Name:     "chatgpt",
            Address:  "北京",
            Mobile:   "15001266627",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       13,
            ID_card:  "6221881460008229857",
            Name:     "刘德华",
            Address:  "北京",
            Mobile:   "15001266547",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       14,
            ID_card:  "6221881460008225654",
            Name:     "李德全",
            Address:  "北京",
            Mobile:   "15001263227",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       15,
            ID_card:  "6221881460008225654",
            Name:     "李静华",
            Address:  "北京",
            Mobile:   "15001269877",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       16,
            ID_card:  "6221881345008225654",
            Name:     "汪德圣",
            Address:  "北京",
            Mobile:   "15001263987",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       18,
            ID_card:  "6221881460008225654",
            Name:     "文心一言",
            Address:  "北京",
            Mobile:   "15001212327",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       16,
            ID_card:  "6221881467652256534",
            Name:     "郑然",
            Address:  "北京",
            Mobile:   "15001267867",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       56,
            ID_card:  "6221881476434225654",
            Name:     "易烊千玺",
            Address:  "北京",
            Mobile:   "15001263227",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       34,
            ID_card:  "6221881468789225654",
            Name:     "李思雨",
            Address:  "北京",
            Mobile:   "15001254237",
            Money:    "30",
            Like:     "足球",
        },
		 {
            ID:       32,
            ID_card:  "6221881469854725654",
            Name:     "徐小平",
            Address:  "北京",
            Mobile:   "15001432327",
            Money:    "30",
            Like:     "羽毛球",
        },
    }
    c.JSON(200, gin.H{
        "message": jsonData[rand.Intn(len(jsonData))],
    })
}

func main() {
    r := gin.Default()
    r.GET("/*any", randomPath)
    r.POST("/*any", randomPath)
    r.DELETE("/*any", randomPath)
    r.PUT("/*any", randomPath)
    r.PATCH("/*any", randomPath)
    r.OPTIONS("/*any", randomPath)
    r.Run(":80")
}
EOF
echo "any_api_server.go 文件创建并写入代码完成"

echo "开始执行 go mod init api_server.go"
go mod init api_server.go
echo "go mod init api_server.go 执行完成"

echo "开始配置 GOPROXY 环境变量为 https://goproxy.cn"
go env -w GOPROXY=https://goproxy.cn
echo "GOPROXY 环境变量配置完成"

echo "开始安装依赖包 github.com/gin-gonic/gin"
go get -u github.com/gin-gonic/gin
while [ ! -f ~/go/pkg/mod/github.com/gin-gonic/gin*/go.mod ]; do sleep 1; done
echo "依赖包 github.com/gin-gonic/gin 安装完成"

echo "开始编译 any_api_server.go 程序"
go build -o any_api_server any_api_server.go
echo "编译 any_api_server.go 程序完成"

echo "启动 any_api_server 服务"
./any_api_server &
echo "any_api_server 服务已启动"
